<?php
namespace Sys\Controller;
use Common\Controller\BaseController;
class CreditRuleController extends BaseController{
	public function __construct(){
		parent::__construct();
	}
	public function index(){
		 $res = M('points_rule')->select();
		$this-> assign('points_rule', $res);
		$this->display();
	}

	public function doDelPointsRule(){
		$ids = I('post.ids');
		$taf = M('points_rule')-> delete($ids);
		if(!$taf){
			$msg = [
				'msg' 	=> '删除失败',
				'error' => 0,
			];

		}
	}
	public function doEditPointsRule(){
		$id=I('post.point_rule_id');
		$case= M('points_rule')->where(['point_rule_id'=>$id])->select();
		if($case){
			if(M('points_rule')-> create()){
			M('points_rule')->save();
			$msg = [
				'msg' 	=> '修改失败',
				'error' => 0,
			];
		}}else{
			if(M('points_rule')-> create()){
			M('points_rule')->add();
			$msg = [
				'msg' 	=> '添加成功',
				'error' => 0,
			];

		}

		}
$this->ajaxReturn($msg);		
	}
	public function lastId(){
		 $lastId=M('points_rule')->max('point_rule_id');
		//dump($lastId);
		$this->ajaxReturn($lastId);
	} 
}
